package com.itany.corejava.code11_io.zuoye;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月27日 9:07
 */
public class Test01 {
    private static Scanner sc = new Scanner(System.in);
    private static List<WorldCup> worldCupList = null;

    public static void main(String[] args) {
        // List<Integer> worldCupList=new ArrayList<>(Arrays.asList(1,100,2,3));
        worldCupList = new ArrayList<>(Arrays.asList(
                new WorldCup("第一届", 1930, "乌拉圭", "乌拉圭"),
                new WorldCup("第二届", 1934, "意大利", "意大利"),
                new WorldCup("第三届", 1938, "法国", "意大利"),
                new WorldCup("第四届", 1950, "巴西", "乌拉圭"),
                new WorldCup("第五届", 1954, "瑞士", "西德"),
                new WorldCup("第六届", 1958, "瑞典", "巴西"),
                new WorldCup("第七届", 1962, "智利", "巴西"),
                new WorldCup("第八届", 1966, "英格兰", "英格兰"),
                new WorldCup("第九届", 1970, "墨西哥", "巴西"),
                new WorldCup("第十届", 1974, "前西德", "西德")

        ));

        showMenu();

    }

    public static void showMenu() {
        System.out.print("请选择:1.输入年份 2.输入国家");
        int choice = sc.nextInt();
        switch (choice) {
            case 1:
                getInfoByYear();
                break;
            case 2:
                getInfoByLoc();
                break;
        }
    }

    public static void getInfoByYear() {
        System.out.print("请输入年份:");
        int year = sc.nextInt();//1938
        boolean flag=false;
        for (WorldCup worldCup : worldCupList) {
            if (worldCup.getYear() == year) {
                flag=true;
                System.out.println(worldCup.getChampion() + "是" + year + "是冠军国家");

            }
        }
        if(!flag){
            System.out.println(year+"没有举办世界杯");
        }
        showMenu();

    }

    public static void getInfoByLoc(){
        System.out.print("请输入国家名称:");
        String loc=sc.next();
        List<Integer> years=new ArrayList<>();
        for(WorldCup worldCup:worldCupList){
            if(worldCup.getChampion().equals(loc)){
                years.add(worldCup.getYear());
            }
        }
        if(years.isEmpty()){
            System.out.println("该国家没有获得过冠军");
        }else{
            System.out.println("获得冠军的年份是:"+years);
        }
        showMenu();
    }
}

class WorldCup {
    private String session;
    private int year;
    private String loc;
    private String champion;

    public WorldCup(String session, int year, String loc, String champion) {
        this.session = session;
        this.year = year;
        this.loc = loc;
        this.champion = champion;
    }

    public String getSession() {
        return session;
    }

    public void setSession(String session) {
        this.session = session;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public String getLoc() {
        return loc;
    }

    public void setLoc(String loc) {
        this.loc = loc;
    }

    public String getChampion() {
        return champion;
    }

    public void setChampion(String champion) {
        this.champion = champion;
    }

    @Override
    public String toString() {
        return "WorldCup{" +
                "session='" + session + '\'' +
                ", year=" + year +
                ", loc='" + loc + '\'' +
                ", champion='" + champion + '\'' +
                '}';
    }
}
